/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
 * Copyright (c) 2020 TELEMATICS LAB, Politecnico di Bari
 *
 * This file is part of 5G-air-simulator
 *
 * 5G-air-simulator is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation;
 *
 * 5G-air-simulator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 5G-air-simulator; if not, see <http://www.gnu.org/licenses/>.
 *
 * Author: Alessandro Grassi <alessandro.grassi@poliba.it>
 */


#ifndef MIESM_EFFECTIVE_SINR_H_
#define MIESM_EFFECTIVE_SINR_H_

#include <math.h>
#include <vector>
#include "../protocolStack/mac/AMCModule.h"

static double MI_sinr[1000] = {
  -20.000000, -19.950000, -19.900000, -19.850000, -19.800000, -19.750000, -19.700000, -19.650000, -19.600000, -19.550000, -19.500000, -19.450000, -19.400000, -19.350000, -19.300000, -19.250000, -19.200000, -19.150000, -19.100000, -19.050000, -19.000000, -18.950000, -18.900000, -18.850000, -18.800000, -18.750000, -18.700000, -18.650000, -18.600000, -18.550000, -18.500000, -18.450000, -18.400000, -18.350000, -18.300000, -18.250000, -18.200000, -18.150000, -18.100000, -18.050000, -18.000000, -17.950000, -17.900000, -17.850000, -17.800000, -17.750000, -17.700000, -17.650000, -17.600000, -17.550000, -17.500000, -17.450000, -17.400000, -17.350000, -17.300000, -17.250000, -17.200000, -17.150000, -17.100000, -17.050000, -17.000000, -16.950000, -16.900000, -16.850000, -16.800000, -16.750000, -16.700000, -16.650000, -16.600000, -16.550000, -16.500000, -16.450000, -16.400000, -16.350000, -16.300000, -16.250000, -16.200000, -16.150000, -16.100000, -16.050000, -16.000000, -15.950000, -15.900000, -15.850000, -15.800000, -15.750000, -15.700000, -15.650000, -15.600000, -15.550000, -15.500000, -15.450000, -15.400000, -15.350000, -15.300000, -15.250000, -15.200000, -15.150000, -15.100000, -15.050000, -15.000000, -14.950000, -14.900000, -14.850000, -14.800000, -14.750000, -14.700000, -14.650000, -14.600000, -14.550000, -14.500000, -14.450000, -14.400000, -14.350000, -14.300000, -14.250000, -14.200000, -14.150000, -14.100000, -14.050000, -14.000000, -13.950000, -13.900000, -13.850000, -13.800000, -13.750000, -13.700000, -13.650000, -13.600000, -13.550000, -13.500000, -13.450000, -13.400000, -13.350000, -13.300000, -13.250000, -13.200000, -13.150000, -13.100000, -13.050000, -13.000000, -12.950000, -12.900000, -12.850000, -12.800000, -12.750000, -12.700000, -12.650000, -12.600000, -12.550000, -12.500000, -12.450000, -12.400000, -12.350000, -12.300000, -12.250000, -12.200000, -12.150000, -12.100000, -12.050000, -12.000000, -11.950000, -11.900000, -11.850000, -11.800000, -11.750000, -11.700000, -11.650000, -11.600000, -11.550000, -11.500000, -11.450000, -11.400000, -11.350000, -11.300000, -11.250000, -11.200000, -11.150000, -11.100000, -11.050000, -11.000000, -10.950000, -10.900000, -10.850000, -10.800000, -10.750000, -10.700000, -10.650000, -10.600000, -10.550000, -10.500000, -10.450000, -10.400000, -10.350000, -10.300000, -10.250000, -10.200000, -10.150000, -10.100000, -10.050000, -10.000000, -9.950000, -9.900000, -9.850000, -9.800000, -9.750000, -9.700000, -9.650000, -9.600000, -9.550000, -9.500000, -9.450000, -9.400000, -9.350000, -9.300000, -9.250000, -9.200000, -9.150000, -9.100000, -9.050000, -9.000000, -8.950000, -8.900000, -8.850000, -8.800000, -8.750000, -8.700000, -8.650000, -8.600000, -8.550000, -8.500000, -8.450000, -8.400000, -8.350000, -8.300000, -8.250000, -8.200000, -8.150000, -8.100000, -8.050000, -8.000000, -7.950000, -7.900000, -7.850000, -7.800000, -7.750000, -7.700000, -7.650000, -7.600000, -7.550000, -7.500000, -7.450000, -7.400000, -7.350000, -7.300000, -7.250000, -7.200000, -7.150000, -7.100000, -7.050000, -7.000000, -6.950000, -6.900000, -6.850000, -6.800000, -6.750000, -6.700000, -6.650000, -6.600000, -6.550000, -6.500000, -6.450000, -6.400000, -6.350000, -6.300000, -6.250000, -6.200000, -6.150000, -6.100000, -6.050000, -6.000000, -5.950000, -5.900000, -5.850000, -5.800000, -5.750000, -5.700000, -5.650000, -5.600000, -5.550000, -5.500000, -5.450000, -5.400000, -5.350000, -5.300000, -5.250000, -5.200000, -5.150000, -5.100000, -5.050000, -5.000000, -4.950000, -4.900000, -4.850000, -4.800000, -4.750000, -4.700000, -4.650000, -4.600000, -4.550000, -4.500000, -4.450000, -4.400000, -4.350000, -4.300000, -4.250000, -4.200000, -4.150000, -4.100000, -4.050000, -4.000000, -3.950000, -3.900000, -3.850000, -3.800000, -3.750000, -3.700000, -3.650000, -3.600000, -3.550000, -3.500000, -3.450000, -3.400000, -3.350000, -3.300000, -3.250000, -3.200000, -3.150000, -3.100000, -3.050000, -3.000000, -2.950000, -2.900000, -2.850000, -2.800000, -2.750000, -2.700000, -2.650000, -2.600000, -2.550000, -2.500000, -2.450000, -2.400000, -2.350000, -2.300000, -2.250000, -2.200000, -2.150000, -2.100000, -2.050000, -2.000000, -1.950000, -1.900000, -1.850000, -1.800000, -1.750000, -1.700000, -1.650000, -1.600000, -1.550000, -1.500000, -1.450000, -1.400000, -1.350000, -1.300000, -1.250000, -1.200000, -1.150000, -1.100000, -1.050000, -1.000000, -0.950000, -0.900000, -0.850000, -0.800000, -0.750000, -0.700000, -0.650000, -0.600000, -0.550000, -0.500000, -0.450000, -0.400000, -0.350000, -0.300000, -0.250000, -0.200000, -0.150000, -0.100000, -0.050000, 0.000000, 0.050000, 0.100000, 0.150000, 0.200000, 0.250000, 0.300000, 0.350000, 0.400000, 0.450000, 0.500000, 0.550000, 0.600000, 0.650000, 0.700000, 0.750000, 0.800000, 0.850000, 0.900000, 0.950000, 1.000000, 1.050000, 1.100000, 1.150000, 1.200000, 1.250000, 1.300000, 1.350000, 1.400000, 1.450000, 1.500000, 1.550000, 1.600000, 1.650000, 1.700000, 1.750000, 1.800000, 1.850000, 1.900000, 1.950000, 2.000000, 2.050000, 2.100000, 2.150000, 2.200000, 2.250000, 2.300000, 2.350000, 2.400000, 2.450000, 2.500000, 2.550000, 2.600000, 2.650000, 2.700000, 2.750000, 2.800000, 2.850000, 2.900000, 2.950000, 3.000000, 3.050000, 3.100000, 3.150000, 3.200000, 3.250000, 3.300000, 3.350000, 3.400000, 3.450000, 3.500000, 3.550000, 3.600000, 3.650000, 3.700000, 3.750000, 3.800000, 3.850000, 3.900000, 3.950000, 4.000000, 4.050000, 4.100000, 4.150000, 4.200000, 4.250000, 4.300000, 4.350000, 4.400000, 4.450000, 4.500000, 4.550000, 4.600000, 4.650000, 4.700000, 4.750000, 4.800000, 4.850000, 4.900000, 4.950000, 5.000000, 5.050000, 5.100000, 5.150000, 5.200000, 5.250000, 5.300000, 5.350000, 5.400000, 5.450000, 5.500000, 5.550000, 5.600000, 5.650000, 5.700000, 5.750000, 5.800000, 5.850000, 5.900000, 5.950000, 6.000000, 6.050000, 6.100000, 6.150000, 6.200000, 6.250000, 6.300000, 6.350000, 6.400000, 6.450000, 6.500000, 6.550000, 6.600000, 6.650000, 6.700000, 6.750000, 6.800000, 6.850000, 6.900000, 6.950000, 7.000000, 7.050000, 7.100000, 7.150000, 7.200000, 7.250000, 7.300000, 7.350000, 7.400000, 7.450000, 7.500000, 7.550000, 7.600000, 7.650000, 7.700000, 7.750000, 7.800000, 7.850000, 7.900000, 7.950000, 8.000000, 8.050000, 8.100000, 8.150000, 8.200000, 8.250000, 8.300000, 8.350000, 8.400000, 8.450000, 8.500000, 8.550000, 8.600000, 8.650000, 8.700000, 8.750000, 8.800000, 8.850000, 8.900000, 8.950000, 9.000000, 9.050000, 9.100000, 9.150000, 9.200000, 9.250000, 9.300000, 9.350000, 9.400000, 9.450000, 9.500000, 9.550000, 9.600000, 9.650000, 9.700000, 9.750000, 9.800000, 9.850000, 9.900000, 9.950000, 10.000000, 10.050000, 10.100000, 10.150000, 10.200000, 10.250000, 10.300000, 10.350000, 10.400000, 10.450000, 10.500000, 10.550000, 10.600000, 10.650000, 10.700000, 10.750000, 10.800000, 10.850000, 10.900000, 10.950000, 11.000000, 11.050000, 11.100000, 11.150000, 11.200000, 11.250000, 11.300000, 11.350000, 11.400000, 11.450000, 11.500000, 11.550000, 11.600000, 11.650000, 11.700000, 11.750000, 11.800000, 11.850000, 11.900000, 11.950000, 12.000000, 12.050000, 12.100000, 12.150000, 12.200000, 12.250000, 12.300000, 12.350000, 12.400000, 12.450000, 12.500000, 12.550000, 12.600000, 12.650000, 12.700000, 12.750000, 12.800000, 12.850000, 12.900000, 12.950000, 13.000000, 13.050000, 13.100000, 13.150000, 13.200000, 13.250000, 13.300000, 13.350000, 13.400000, 13.450000, 13.500000, 13.550000, 13.600000, 13.650000, 13.700000, 13.750000, 13.800000, 13.850000, 13.900000, 13.950000, 14.000000, 14.050000, 14.100000, 14.150000, 14.200000, 14.250000, 14.300000, 14.350000, 14.400000, 14.450000, 14.500000, 14.550000, 14.600000, 14.650000, 14.700000, 14.750000, 14.800000, 14.850000, 14.900000, 14.950000, 15.000000, 15.050000, 15.100000, 15.150000, 15.200000, 15.250000, 15.300000, 15.350000, 15.400000, 15.450000, 15.500000, 15.550000, 15.600000, 15.650000, 15.700000, 15.750000, 15.800000, 15.850000, 15.900000, 15.950000, 16.000000, 16.050000, 16.100000, 16.150000, 16.200000, 16.250000, 16.300000, 16.350000, 16.400000, 16.450000, 16.500000, 16.550000, 16.600000, 16.650000, 16.700000, 16.750000, 16.800000, 16.850000, 16.900000, 16.950000, 17.000000, 17.050000, 17.100000, 17.150000, 17.200000, 17.250000, 17.300000, 17.350000, 17.400000, 17.450000, 17.500000, 17.550000, 17.600000, 17.650000, 17.700000, 17.750000, 17.800000, 17.850000, 17.900000, 17.950000, 18.000000, 18.050000, 18.100000, 18.150000, 18.200000, 18.250000, 18.300000, 18.350000, 18.400000, 18.450000, 18.500000, 18.550000, 18.600000, 18.650000, 18.700000, 18.750000, 18.800000, 18.850000, 18.900000, 18.950000, 19.000000, 19.050000, 19.100000, 19.150000, 19.200000, 19.250000, 19.300000, 19.350000, 19.400000, 19.450000, 19.500000, 19.550000, 19.600000, 19.650000, 19.700000, 19.750000, 19.800000, 19.850000, 19.900000, 19.950000, 20.000000, 20.050000, 20.100000, 20.150000, 20.200000, 20.250000, 20.300000, 20.350000, 20.400000, 20.450000, 20.500000, 20.550000, 20.600000, 20.650000, 20.700000, 20.750000, 20.800000, 20.850000, 20.900000, 20.950000, 21.000000, 21.050000, 21.100000, 21.150000, 21.200000, 21.250000, 21.300000, 21.350000, 21.400000, 21.450000, 21.500000, 21.550000, 21.600000, 21.650000, 21.700000, 21.750000, 21.800000, 21.850000, 21.900000, 21.950000, 22.000000, 22.050000, 22.100000, 22.150000, 22.200000, 22.250000, 22.300000, 22.350000, 22.400000, 22.450000, 22.500000, 22.550000, 22.600000, 22.650000, 22.700000, 22.750000, 22.800000, 22.850000, 22.900000, 22.950000, 23.000000, 23.050000, 23.100000, 23.150000, 23.200000, 23.250000, 23.300000, 23.350000, 23.400000, 23.450000, 23.500000, 23.550000, 23.600000, 23.650000, 23.700000, 23.750000, 23.800000, 23.850000, 23.900000, 23.950000, 24.000000, 24.050000, 24.100000, 24.150000, 24.200000, 24.250000, 24.300000, 24.350000, 24.400000, 24.450000, 24.500000, 24.550000, 24.600000, 24.650000, 24.700000, 24.750000, 24.800000, 24.850000, 24.900000, 24.950000, 25.000000, 25.050000, 25.100000, 25.150000, 25.200000, 25.250000, 25.300000, 25.350000, 25.400000, 25.450000, 25.500000, 25.550000, 25.600000, 25.650000, 25.700000, 25.750000, 25.800000, 25.850000, 25.900000, 25.950000, 26.000000, 26.050000, 26.100000, 26.150000, 26.200000, 26.250000, 26.300000, 26.350000, 26.400000, 26.450000, 26.500000, 26.550000, 26.600000, 26.650000, 26.700000, 26.750000, 26.800000, 26.850000, 26.900000, 26.950000, 27.000000, 27.050000, 27.100000, 27.150000, 27.200000, 27.250000, 27.300000, 27.350000, 27.400000, 27.450000, 27.500000, 27.550000, 27.600000, 27.650000, 27.700000, 27.750000, 27.800000, 27.850000, 27.900000, 27.950000, 28.000000, 28.050000, 28.100000, 28.150000, 28.200000, 28.250000, 28.300000, 28.350000, 28.400000, 28.450000, 28.500000, 28.550000, 28.600000, 28.650000, 28.700000, 28.750000, 28.800000, 28.850000, 28.900000, 28.950000, 29.000000, 29.050000, 29.100000, 29.150000, 29.200000, 29.250000, 29.300000, 29.350000, 29.400000, 29.450000, 29.500000, 29.550000, 29.600000, 29.650000, 29.700000, 29.750000, 29.800000, 29.850000, 29.900000, 29.950000,
};

static double MI_QPSK[1000] = {
  0.006753, 0.006837, 0.006921, 0.007007, 0.007094, 0.007181, 0.007270, 0.007360, 0.007450, 0.007542, 0.007635, 0.007729, 0.007824, 0.007920, 0.008017, 0.008116, 0.008215, 0.008316, 0.008418, 0.008521, 0.008625, 0.008731, 0.008837, 0.008945, 0.009054, 0.009165, 0.009276, 0.009389, 0.009504, 0.009619, 0.009736, 0.009854, 0.009974, 0.010095, 0.010217, 0.010341, 0.010466, 0.010593, 0.010721, 0.010851, 0.010982, 0.011115, 0.011249, 0.011384, 0.011522, 0.011660, 0.011801, 0.011943, 0.012086, 0.012232, 0.012378, 0.012527, 0.012677, 0.012829, 0.012983, 0.013138, 0.013296, 0.013455, 0.013616, 0.013778, 0.013943, 0.014109, 0.014278, 0.014448, 0.014620, 0.014794, 0.014970, 0.015148, 0.015328, 0.015510, 0.015695, 0.015881, 0.016069, 0.016260, 0.016452, 0.016647, 0.016844, 0.017043, 0.017245, 0.017449, 0.017655, 0.017863, 0.018074, 0.018287, 0.018502, 0.018720, 0.018941, 0.019164, 0.019389, 0.019617, 0.019847, 0.020080, 0.020316, 0.020554, 0.020795, 0.021038, 0.021285, 0.021534, 0.021786, 0.022040, 0.022298, 0.022558, 0.022821, 0.023088, 0.023357, 0.023629, 0.023904, 0.024182, 0.024463, 0.024748, 0.025035, 0.025326, 0.025620, 0.025917, 0.026218, 0.026522, 0.026829, 0.027139, 0.027453, 0.027771, 0.028092, 0.028416, 0.028744, 0.029076, 0.029411, 0.029750, 0.030093, 0.030440, 0.030790, 0.031144, 0.031502, 0.031864, 0.032230, 0.032600, 0.032974, 0.033352, 0.033734, 0.034120, 0.034511, 0.034905, 0.035304, 0.035708, 0.036115, 0.036528, 0.036944, 0.037365, 0.037791, 0.038222, 0.038657, 0.039096, 0.039541, 0.039990, 0.040444, 0.040903, 0.041367, 0.041836, 0.042310, 0.042789, 0.043273, 0.043763, 0.044257, 0.044757, 0.045263, 0.045773, 0.046289, 0.046811, 0.047338, 0.047871, 0.048410, 0.048954, 0.049504, 0.050060, 0.050622, 0.051190, 0.051764, 0.052344, 0.052930, 0.053522, 0.054121, 0.054725, 0.055337, 0.055954, 0.056579, 0.057209, 0.057847, 0.058491, 0.059142, 0.059799, 0.060464, 0.061135, 0.061814, 0.062500, 0.063192, 0.063892, 0.064600, 0.065314, 0.066036, 0.066766, 0.067503, 0.068248, 0.069000, 0.069761, 0.070529, 0.071305, 0.072089, 0.072881, 0.073681, 0.074490, 0.075307, 0.076132, 0.076966, 0.077808, 0.078659, 0.079518, 0.080386, 0.081263, 0.082149, 0.083044, 0.083948, 0.084862, 0.085784, 0.086716, 0.087657, 0.088608, 0.089568, 0.090538, 0.091518, 0.092508, 0.093507, 0.094517, 0.095536, 0.096566, 0.097606, 0.098656, 0.099717, 0.100789, 0.101871, 0.102963, 0.104067, 0.105181, 0.106306, 0.107443, 0.108590, 0.109749, 0.110920, 0.112101, 0.113294, 0.114499, 0.115716, 0.116944, 0.118185, 0.119437, 0.120701, 0.121978, 0.123267, 0.124568, 0.125882, 0.127209, 0.128548, 0.129900, 0.131265, 0.132643, 0.134034, 0.135438, 0.136855, 0.138286, 0.139730, 0.141188, 0.142660, 0.144145, 0.145644, 0.147158, 0.148685, 0.150227, 0.151782, 0.153353, 0.154938, 0.156537, 0.158151, 0.159780, 0.161424, 0.163082, 0.164756, 0.166445, 0.168150, 0.169870, 0.171605, 0.173356, 0.175123, 0.176905, 0.178704, 0.180518, 0.182349, 0.184195, 0.186058, 0.187938, 0.189834, 0.191746, 0.193675, 0.195622, 0.197584, 0.199564, 0.201561, 0.203575, 0.205607, 0.207656, 0.209722, 0.211805, 0.213907, 0.216026, 0.218163, 0.220317, 0.222490, 0.224681, 0.226890, 0.229117, 0.231362, 0.233626, 0.235908, 0.238209, 0.240528, 0.242866, 0.245223, 0.247598, 0.249992, 0.252406, 0.254838, 0.257289, 0.259760, 0.262250, 0.264758, 0.267287, 0.269834, 0.272401, 0.274987, 0.277593, 0.280218, 0.282863, 0.285527, 0.288211, 0.290915, 0.293638, 0.296381, 0.299144, 0.301926, 0.304728, 0.307550, 0.310392, 0.313253, 0.316134, 0.319035, 0.321955, 0.324895, 0.327855, 0.330834, 0.333833, 0.336852, 0.339890, 0.342948, 0.346025, 0.349121, 0.352237, 0.355372, 0.358526, 0.361699, 0.364892, 0.367449, 0.370671, 0.373911, 0.377168, 0.380442, 0.383734, 0.387042, 0.390367, 0.393709, 0.397067, 0.400442, 0.403833, 0.407241, 0.410665, 0.414105, 0.417561, 0.421033, 0.424520, 0.428023, 0.431542, 0.435076, 0.438624, 0.442188, 0.445767, 0.449360, 0.452967, 0.456589, 0.460225, 0.463874, 0.467537, 0.471214, 0.474904, 0.478607, 0.482322, 0.486051, 0.489791, 0.493544, 0.497308, 0.501084, 0.504872, 0.508670, 0.512479, 0.516299, 0.520129, 0.523969, 0.527818, 0.531677, 0.535545, 0.539422, 0.543307, 0.547200, 0.551101, 0.555009, 0.558924, 0.562846, 0.566775, 0.570709, 0.574650, 0.578595, 0.582546, 0.586500, 0.590459, 0.594422, 0.598388, 0.602357, 0.606329, 0.610303, 0.614278, 0.618255, 0.622232, 0.626210, 0.630188, 0.634165, 0.638142, 0.642117, 0.646090, 0.650061, 0.654029, 0.657994, 0.661955, 0.665911, 0.669863, 0.673810, 0.677751, 0.681686, 0.685614, 0.689536, 0.693449, 0.697354, 0.701250, 0.705137, 0.709015, 0.712882, 0.716738, 0.720583, 0.724416, 0.728237, 0.732045, 0.735840, 0.739620, 0.743386, 0.747137, 0.750873, 0.754593, 0.758296, 0.761982, 0.765650, 0.769300, 0.772932, 0.776544, 0.780137, 0.783710, 0.787262, 0.790792, 0.794301, 0.797788, 0.801253, 0.804694, 0.808111, 0.811505, 0.814873, 0.818217, 0.821535, 0.824828, 0.828094, 0.831333, 0.834544, 0.837729, 0.840885, 0.844012, 0.847111, 0.850180, 0.853219, 0.856229, 0.859208, 0.862156, 0.865073, 0.867959, 0.870813, 0.873635, 0.876425, 0.879181, 0.881905, 0.884596, 0.887253, 0.889877, 0.892467, 0.895022, 0.897544, 0.900030, 0.902482, 0.904900, 0.907282, 0.909629, 0.911941, 0.914218, 0.916459, 0.918665, 0.920835, 0.922969, 0.925068, 0.927131, 0.929159, 0.931151, 0.933108, 0.935029, 0.936914, 0.938764, 0.940579, 0.942358, 0.944103, 0.945812, 0.947486, 0.949126, 0.950732, 0.952303, 0.953840, 0.955343, 0.956812, 0.958248, 0.959651, 0.961021, 0.962358, 0.963663, 0.964936, 0.966177, 0.967387, 0.968566, 0.969714, 0.970832, 0.971919, 0.972977, 0.974006, 0.975006, 0.975978, 0.976921, 0.977837, 0.978726, 0.979588, 0.980424, 0.981234, 0.982018, 0.982778, 0.983513, 0.984224, 0.984911, 0.985575, 0.986217, 0.986836, 0.987434, 0.988010, 0.988566, 0.989102, 0.989617, 0.990114, 0.990591, 0.991050, 0.991492, 0.991915, 0.992322, 0.992713, 0.993087, 0.993446, 0.993789, 0.994118, 0.994433, 0.994734, 0.995022, 0.995296, 0.995559, 0.995809, 0.996047, 0.996274, 0.996491, 0.996697, 0.996892, 0.997078, 0.997255, 0.997423, 0.997582, 0.997733, 0.997875, 0.998011, 0.998138, 0.998259, 0.998373, 0.998481, 0.998583, 0.998679, 0.998769, 0.998854, 0.998933, 0.999009, 0.999079, 0.999145, 0.999207, 0.999265, 0.999320, 0.999370, 0.999418, 0.999462, 0.999504, 0.999542, 0.999578, 0.999612, 0.999643, 0.999672, 0.999698, 0.999723, 0.999746, 0.999768, 0.999787, 0.999806, 0.999823, 0.999838, 0.999852, 0.999866, 0.999878, 0.999889, 0.999899, 0.999908, 0.999917, 0.999925, 0.999932, 0.999939, 0.999945, 0.999950, 0.999955, 0.999960, 0.999964, 0.999967, 0.999971, 0.999974, 0.999977, 0.999979, 0.999981, 0.999983, 0.999985, 0.999987, 0.999988, 0.999990, 0.999991, 0.999992, 0.999993, 0.999994, 0.999994, 0.999995, 0.999996, 0.999996, 0.999997, 0.999997, 0.999997, 0.999998, 0.999998, 0.999998, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
};

static double MI_16QAM[1000] = {
  0.002735, 0.002770, 0.002806, 0.002842, 0.002878, 0.002915, 0.002953, 0.002991, 0.003029, 0.003068, 0.003107, 0.003147, 0.003187, 0.003228, 0.003269, 0.003311, 0.003353, 0.003396, 0.003439, 0.003483, 0.003527, 0.003572, 0.003617, 0.003663, 0.003709, 0.003756, 0.003803, 0.003851, 0.003900, 0.003949, 0.003998, 0.004049, 0.004100, 0.004151, 0.004203, 0.004256, 0.004309, 0.004363, 0.004418, 0.004473, 0.004529, 0.004585, 0.004642, 0.004700, 0.004759, 0.004818, 0.004878, 0.004938, 0.004999, 0.005061, 0.005124, 0.005188, 0.005252, 0.005317, 0.005382, 0.005449, 0.005516, 0.005584, 0.005653, 0.005722, 0.005793, 0.005864, 0.005936, 0.006009, 0.006082, 0.006157, 0.006232, 0.006309, 0.006386, 0.006464, 0.006543, 0.006623, 0.006703, 0.006785, 0.006868, 0.006951, 0.007036, 0.007121, 0.007208, 0.007295, 0.007384, 0.007473, 0.007564, 0.007655, 0.007748, 0.007842, 0.007936, 0.008032, 0.008129, 0.008227, 0.008326, 0.008426, 0.008528, 0.008630, 0.008734, 0.008839, 0.008945, 0.009052, 0.009161, 0.009271, 0.009382, 0.009494, 0.009608, 0.009722, 0.009838, 0.009956, 0.010075, 0.010195, 0.010316, 0.010439, 0.010563, 0.010689, 0.010816, 0.010944, 0.011074, 0.011206, 0.011339, 0.011473, 0.011609, 0.011746, 0.011885, 0.012025, 0.012168, 0.012311, 0.012456, 0.012603, 0.012752, 0.012902, 0.013054, 0.013207, 0.013363, 0.013520, 0.013678, 0.013839, 0.014001, 0.014165, 0.014331, 0.014499, 0.014668, 0.014840, 0.015013, 0.015189, 0.015366, 0.015545, 0.015726, 0.015910, 0.016095, 0.016282, 0.016471, 0.016663, 0.016856, 0.017052, 0.017250, 0.017450, 0.017652, 0.017856, 0.018063, 0.018272, 0.018483, 0.018697, 0.018913, 0.019131, 0.019351, 0.019574, 0.019800, 0.020028, 0.020258, 0.020491, 0.020727, 0.020965, 0.021205, 0.021448, 0.021694, 0.021943, 0.022194, 0.022448, 0.022704, 0.022964, 0.023226, 0.023491, 0.023759, 0.024030, 0.024304, 0.024580, 0.024860, 0.025143, 0.025428, 0.025717, 0.026009, 0.026304, 0.026602, 0.026903, 0.027208, 0.027516, 0.027827, 0.028141, 0.028459, 0.028780, 0.029104, 0.029432, 0.029764, 0.030099, 0.030437, 0.030779, 0.031125, 0.031474, 0.031827, 0.032184, 0.032545, 0.032909, 0.033277, 0.033649, 0.034025, 0.034405, 0.034789, 0.035177, 0.035569, 0.035965, 0.036365, 0.036769, 0.037177, 0.037590, 0.038007, 0.038429, 0.038854, 0.039285, 0.039719, 0.040158, 0.040602, 0.041050, 0.041503, 0.041961, 0.042423, 0.042890, 0.043361, 0.043838, 0.044319, 0.044806, 0.045297, 0.045793, 0.046295, 0.046801, 0.047313, 0.047830, 0.048352, 0.048879, 0.049412, 0.049950, 0.050493, 0.051042, 0.051597, 0.052157, 0.052723, 0.053294, 0.053871, 0.054454, 0.055042, 0.055637, 0.056237, 0.056844, 0.057456, 0.058074, 0.058699, 0.059330, 0.059967, 0.060610, 0.061259, 0.061915, 0.062578, 0.063246, 0.063922, 0.064604, 0.065292, 0.065988, 0.066690, 0.067398, 0.068114, 0.068837, 0.069566, 0.070303, 0.071046, 0.071797, 0.072555, 0.073320, 0.074093, 0.074873, 0.075660, 0.076455, 0.077257, 0.078067, 0.078884, 0.079709, 0.080542, 0.081383, 0.082231, 0.083088, 0.083952, 0.084825, 0.085705, 0.086594, 0.087491, 0.088396, 0.089309, 0.090231, 0.091161, 0.092100, 0.093047, 0.094003, 0.094967, 0.095940, 0.096922, 0.097913, 0.098913, 0.099921, 0.100939, 0.101966, 0.103001, 0.104046, 0.105100, 0.106164, 0.107236, 0.108318, 0.109410, 0.110511, 0.111621, 0.112741, 0.113871, 0.115010, 0.116159, 0.117318, 0.118487, 0.119665, 0.120854, 0.122052, 0.123261, 0.124480, 0.125708, 0.126947, 0.128196, 0.129456, 0.130726, 0.132006, 0.133296, 0.134597, 0.135908, 0.137230, 0.138563, 0.139906, 0.141259, 0.142623, 0.143998, 0.145222, 0.146617, 0.148022, 0.149438, 0.150864, 0.152301, 0.153748, 0.155206, 0.156675, 0.158154, 0.159644, 0.161144, 0.162656, 0.164178, 0.165711, 0.167255, 0.168810, 0.170376, 0.171952, 0.173540, 0.175139, 0.176748, 0.178369, 0.180001, 0.181643, 0.183297, 0.184962, 0.186638, 0.188326, 0.190024, 0.191734, 0.193455, 0.195187, 0.196930, 0.198685, 0.200450, 0.202227, 0.204016, 0.205815, 0.207626, 0.209448, 0.211281, 0.213126, 0.214982, 0.216849, 0.218728, 0.220618, 0.222519, 0.224431, 0.226355, 0.228289, 0.230236, 0.232193, 0.234161, 0.236141, 0.238132, 0.240134, 0.242147, 0.244172, 0.246207, 0.248254, 0.250311, 0.252380, 0.254460, 0.256551, 0.258652, 0.260765, 0.262889, 0.265023, 0.267168, 0.269324, 0.271491, 0.273669, 0.275857, 0.278056, 0.280266, 0.282486, 0.284717, 0.286958, 0.289210, 0.291472, 0.293744, 0.296027, 0.298320, 0.300623, 0.302937, 0.305260, 0.307594, 0.309937, 0.312291, 0.314654, 0.317027, 0.319410, 0.321803, 0.324205, 0.326617, 0.329038, 0.331469, 0.333910, 0.336359, 0.338818, 0.341286, 0.343763, 0.346249, 0.348745, 0.351249, 0.353762, 0.356284, 0.358814, 0.361353, 0.363901, 0.366457, 0.369022, 0.371595, 0.374177, 0.376766, 0.379364, 0.381970, 0.384584, 0.387205, 0.389835, 0.392472, 0.395117, 0.397770, 0.400431, 0.403098, 0.405774, 0.408456, 0.411146, 0.413843, 0.416547, 0.419258, 0.421976, 0.424701, 0.427433, 0.430172, 0.432917, 0.435669, 0.438428, 0.441193, 0.443964, 0.446579, 0.449361, 0.452149, 0.454943, 0.457743, 0.460548, 0.463359, 0.466175, 0.468997, 0.471824, 0.474656, 0.477494, 0.480336, 0.483184, 0.486038, 0.488896, 0.491759, 0.494627, 0.497500, 0.500378, 0.503260, 0.506147, 0.509039, 0.511936, 0.514837, 0.517742, 0.520652, 0.523566, 0.526485, 0.529408, 0.532335, 0.535266, 0.538202, 0.540815, 0.543755, 0.546698, 0.549644, 0.552593, 0.555545, 0.558501, 0.561459, 0.564420, 0.567384, 0.570351, 0.573320, 0.576293, 0.579268, 0.582245, 0.585225, 0.588208, 0.591193, 0.594181, 0.597170, 0.600163, 0.603157, 0.606153, 0.609152, 0.612152, 0.615155, 0.618159, 0.621165, 0.624173, 0.627182, 0.630193, 0.633206, 0.636219, 0.639234, 0.642250, 0.645267, 0.648285, 0.651304, 0.654324, 0.657344, 0.660364, 0.663385, 0.666406, 0.669427, 0.672448, 0.675469, 0.678490, 0.681510, 0.684529, 0.687547, 0.690564, 0.693581, 0.696595, 0.699608, 0.702620, 0.705629, 0.708636, 0.711641, 0.714643, 0.717643, 0.720639, 0.723632, 0.726622, 0.729608, 0.732590, 0.735568, 0.738541, 0.741510, 0.744473, 0.747432, 0.750385, 0.753332, 0.756273, 0.759208, 0.762136, 0.765057, 0.767971, 0.770877, 0.773776, 0.776666, 0.779548, 0.782422, 0.785286, 0.788141, 0.790986, 0.793821, 0.796646, 0.799461, 0.802264, 0.805056, 0.807836, 0.810604, 0.813360, 0.816104, 0.818834, 0.821551, 0.824254, 0.826944, 0.829619, 0.832279, 0.834924, 0.837555, 0.840169, 0.842767, 0.845350, 0.847915, 0.850464, 0.852995, 0.855509, 0.858004, 0.860482, 0.862941, 0.865381, 0.867803, 0.870204, 0.872586, 0.874948, 0.877290, 0.879611, 0.881912, 0.884191, 0.886449, 0.888685, 0.890900, 0.893092, 0.895263, 0.897410, 0.899535, 0.901637, 0.903716, 0.905771, 0.907803, 0.909811, 0.911796, 0.913756, 0.915692, 0.917604, 0.919491, 0.921353, 0.923191, 0.925004, 0.926792, 0.928554, 0.930292, 0.932005, 0.933692, 0.935354, 0.936990, 0.938601, 0.940187, 0.941747, 0.943282, 0.944791, 0.946275, 0.947734, 0.949167, 0.950574, 0.951957, 0.953314, 0.954646, 0.955953, 0.957235, 0.958492, 0.959724, 0.960932, 0.962115, 0.963274, 0.964408, 0.965518, 0.966605, 0.967668, 0.968707, 0.969722, 0.970715, 0.971684, 0.972631, 0.973555, 0.974457, 0.975337, 0.976194, 0.977031, 0.977845, 0.978639, 0.979412, 0.980164, 0.980896, 0.981608, 0.982300, 0.982973, 0.983626, 0.984261, 0.984877, 0.985475, 0.986055, 0.986617, 0.987162, 0.987690, 0.988201, 0.988696, 0.989174, 0.989637, 0.990085, 0.990517, 0.990935, 0.991338, 0.991727, 0.992102, 0.992463, 0.992812, 0.993148, 0.993471, 0.993782, 0.994081, 0.994368, 0.994644, 0.994910, 0.995164, 0.995408, 0.995643, 0.995867, 0.996082, 0.996288, 0.996484, 0.996673, 0.996853, 0.997024, 0.997188, 0.997345, 0.997494, 0.997637, 0.997772, 0.997901, 0.998024, 0.998140, 0.998251, 0.998356, 0.998456, 0.998551, 0.998641, 0.998726, 0.998806, 0.998883, 0.998955, 0.999023, 0.999087, 0.999147, 0.999205, 0.999258, 0.999309, 0.999357, 0.999401, 0.999444, 0.999483, 0.999520, 0.999555, 0.999587, 0.999618, 0.999646, 0.999673, 0.999698, 0.999721, 0.999743, 0.999763, 0.999782, 0.999799, 0.999815, 0.999830, 0.999844, 0.999857, 0.999869, 0.999880, 0.999890, 0.999900, 0.999909, 0.999917, 0.999924, 0.999931, 0.999937, 0.999943, 0.999948, 0.999953, 0.999957, 0.999961, 0.999965, 0.999968, 0.999972, 0.999974, 0.999977, 0.999979, 0.999981, 0.999983, 0.999985, 0.999987, 0.999988, 0.999989, 0.999990, 0.999991, 0.999992, 0.999993, 0.999994, 0.999995, 0.999995, 0.999996, 0.999996, 0.999997, 0.999997, 0.999997, 0.999998, 0.999998, 0.999998, 0.999998, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
};

static double MI_64QAM[1000] = {
  0.001244, 0.001261, 0.001278, 0.001296, 0.001313, 0.001331, 0.001349, 0.001368, 0.001386, 0.001405, 0.001424, 0.001443, 0.001463, 0.001483, 0.001503, 0.001523, 0.001543, 0.001564, 0.001585, 0.001606, 0.001628, 0.001650, 0.001672, 0.001694, 0.001716, 0.001739, 0.001762, 0.001786, 0.001809, 0.001833, 0.001858, 0.001882, 0.001907, 0.001932, 0.001957, 0.001983, 0.002009, 0.002036, 0.002062, 0.002089, 0.002117, 0.002144, 0.002172, 0.002200, 0.002229, 0.002258, 0.002287, 0.002317, 0.002347, 0.002378, 0.002408, 0.002440, 0.002471, 0.002503, 0.002535, 0.002568, 0.002601, 0.002634, 0.002668, 0.002702, 0.002737, 0.002772, 0.002808, 0.002843, 0.002880, 0.002916, 0.002954, 0.002991, 0.003029, 0.003068, 0.003107, 0.003146, 0.003186, 0.003227, 0.003267, 0.003309, 0.003351, 0.003393, 0.003436, 0.003479, 0.003523, 0.003567, 0.003612, 0.003657, 0.003703, 0.003750, 0.003797, 0.003844, 0.003892, 0.003941, 0.003990, 0.004040, 0.004091, 0.004141, 0.004193, 0.004245, 0.004298, 0.004351, 0.004405, 0.004460, 0.004515, 0.004571, 0.004628, 0.004685, 0.004743, 0.004802, 0.004861, 0.004921, 0.004982, 0.005043, 0.005105, 0.005168, 0.005231, 0.005296, 0.005361, 0.005426, 0.005493, 0.005560, 0.005628, 0.005697, 0.005767, 0.005837, 0.005908, 0.005980, 0.006053, 0.006127, 0.006201, 0.006277, 0.006353, 0.006430, 0.006508, 0.006587, 0.006667, 0.006748, 0.006830, 0.006912, 0.006996, 0.007080, 0.007166, 0.007252, 0.007340, 0.007428, 0.007518, 0.007608, 0.007700, 0.007792, 0.007886, 0.007980, 0.008076, 0.008173, 0.008271, 0.008370, 0.008470, 0.008571, 0.008674, 0.008777, 0.008882, 0.008988, 0.009095, 0.009204, 0.009313, 0.009424, 0.009536, 0.009649, 0.009764, 0.009880, 0.009997, 0.010116, 0.010236, 0.010357, 0.010479, 0.010603, 0.010729, 0.010855, 0.010983, 0.011113, 0.011244, 0.011376, 0.011510, 0.011646, 0.011783, 0.011921, 0.012061, 0.012203, 0.012346, 0.012491, 0.012637, 0.012785, 0.012935, 0.013086, 0.013239, 0.013394, 0.013551, 0.013709, 0.013869, 0.014030, 0.014194, 0.014359, 0.014526, 0.014695, 0.014866, 0.015038, 0.015213, 0.015389, 0.015568, 0.015748, 0.015931, 0.016115, 0.016301, 0.016490, 0.016680, 0.016873, 0.017067, 0.017264, 0.017463, 0.017664, 0.017868, 0.018073, 0.018281, 0.018491, 0.018703, 0.018918, 0.019135, 0.019354, 0.019576, 0.019800, 0.020026, 0.020255, 0.020487, 0.020721, 0.020957, 0.021196, 0.021438, 0.021682, 0.021929, 0.022178, 0.022430, 0.022685, 0.022943, 0.023203, 0.023466, 0.023732, 0.024001, 0.024273, 0.024547, 0.024825, 0.025105, 0.025388, 0.025675, 0.025964, 0.026257, 0.026553, 0.026851, 0.027153, 0.027458, 0.027767, 0.028079, 0.028393, 0.028712, 0.029033, 0.029358, 0.029687, 0.030018, 0.030354, 0.030693, 0.031035, 0.031381, 0.031731, 0.032084, 0.032441, 0.032801, 0.033166, 0.033534, 0.033906, 0.034282, 0.034662, 0.035045, 0.035433, 0.035825, 0.036220, 0.036620, 0.037024, 0.037432, 0.037844, 0.038261, 0.038682, 0.039107, 0.039536, 0.039970, 0.040408, 0.040851, 0.041298, 0.041750, 0.042206, 0.042667, 0.043133, 0.043603, 0.044078, 0.044558, 0.045043, 0.045533, 0.046027, 0.046527, 0.047031, 0.047541, 0.048055, 0.048575, 0.049100, 0.049630, 0.050166, 0.050707, 0.051253, 0.051804, 0.052361, 0.052924, 0.053492, 0.054066, 0.054645, 0.055230, 0.055821, 0.056417, 0.057020, 0.057628, 0.058242, 0.058862, 0.059488, 0.060120, 0.060758, 0.061403, 0.062053, 0.062710, 0.063373, 0.064043, 0.064719, 0.065401, 0.066090, 0.066786, 0.067488, 0.068196, 0.068912, 0.069634, 0.070363, 0.071099, 0.071841, 0.072591, 0.073348, 0.074111, 0.074882, 0.075660, 0.076445, 0.077238, 0.078038, 0.078845, 0.079659, 0.080481, 0.081311, 0.082148, 0.082992, 0.083844, 0.084704, 0.085572, 0.086448, 0.087331, 0.088223, 0.089122, 0.090029, 0.090944, 0.091868, 0.092800, 0.093739, 0.094687, 0.095644, 0.096609, 0.097582, 0.098563, 0.099553, 0.100552, 0.101559, 0.102575, 0.103599, 0.104632, 0.105674, 0.106725, 0.107785, 0.108853, 0.109931, 0.111017, 0.112112, 0.113217, 0.114330, 0.115453, 0.116585, 0.117726, 0.118876, 0.120036, 0.121205, 0.122383, 0.123571, 0.124768, 0.125975, 0.127191, 0.128416, 0.129651, 0.130896, 0.132150, 0.133414, 0.134688, 0.135971, 0.137264, 0.138567, 0.139879, 0.141201, 0.142533, 0.143875, 0.145226, 0.146587, 0.147958, 0.149339, 0.150730, 0.151914, 0.153322, 0.154739, 0.156166, 0.157602, 0.159048, 0.160503, 0.161967, 0.163441, 0.164924, 0.166417, 0.167919, 0.169430, 0.170951, 0.172481, 0.174021, 0.175570, 0.177128, 0.178696, 0.180273, 0.181859, 0.183455, 0.185060, 0.186675, 0.188299, 0.189932, 0.191574, 0.193226, 0.194887, 0.196557, 0.198236, 0.199925, 0.201622, 0.203329, 0.205045, 0.206769, 0.208503, 0.210246, 0.211998, 0.213758, 0.215528, 0.217306, 0.219093, 0.220889, 0.222693, 0.224506, 0.226328, 0.228158, 0.229996, 0.231843, 0.233699, 0.235563, 0.237434, 0.239315, 0.241203, 0.243099, 0.245003, 0.246915, 0.248835, 0.250763, 0.252698, 0.254641, 0.256592, 0.258550, 0.260515, 0.262488, 0.264468, 0.266455, 0.268449, 0.270450, 0.272458, 0.274473, 0.276494, 0.278522, 0.280556, 0.282597, 0.284644, 0.286698, 0.288757, 0.290823, 0.292894, 0.294971, 0.297054, 0.299142, 0.301236, 0.303335, 0.305440, 0.307550, 0.309664, 0.311784, 0.313908, 0.316038, 0.318171, 0.320310, 0.322452, 0.324599, 0.326750, 0.328905, 0.331064, 0.333227, 0.335394, 0.337564, 0.339737, 0.341914, 0.344094, 0.346278, 0.348464, 0.350653, 0.352845, 0.355040, 0.357237, 0.359437, 0.361639, 0.363843, 0.366050, 0.368258, 0.370469, 0.372681, 0.374895, 0.377111, 0.379328, 0.381546, 0.383766, 0.385988, 0.388210, 0.390434, 0.392658, 0.394883, 0.397110, 0.399337, 0.401564, 0.403793, 0.406021, 0.408251, 0.410480, 0.412710, 0.414940, 0.417171, 0.419401, 0.421632, 0.423863, 0.426094, 0.428325, 0.430555, 0.432786, 0.435016, 0.437247, 0.439477, 0.441707, 0.443936, 0.446166, 0.448395, 0.450624, 0.452852, 0.455081, 0.457309, 0.459537, 0.461765, 0.463992, 0.466219, 0.468446, 0.470673, 0.472900, 0.475126, 0.477353, 0.479579, 0.481806, 0.484032, 0.486259, 0.488486, 0.490713, 0.492940, 0.495168, 0.497396, 0.499624, 0.501853, 0.504083, 0.506313, 0.508326, 0.510556, 0.512785, 0.515016, 0.517247, 0.519478, 0.521710, 0.523944, 0.526178, 0.528413, 0.530650, 0.532888, 0.535127, 0.537368, 0.539610, 0.541855, 0.544101, 0.546349, 0.548599, 0.550852, 0.553107, 0.555364, 0.557624, 0.559886, 0.562152, 0.564420, 0.566691, 0.568966, 0.571243, 0.573525, 0.575809, 0.578097, 0.580389, 0.582684, 0.584984, 0.587287, 0.589594, 0.591906, 0.594221, 0.596541, 0.598865, 0.601194, 0.603527, 0.605865, 0.608208, 0.610555, 0.612906, 0.615263, 0.617625, 0.619991, 0.622362, 0.624738, 0.627119, 0.629505, 0.631896, 0.634292, 0.636693, 0.639099, 0.641509, 0.643925, 0.646345, 0.648771, 0.651201, 0.653636, 0.655857, 0.658299, 0.660745, 0.663194, 0.665648, 0.668106, 0.670567, 0.673032, 0.675501, 0.677973, 0.680449, 0.682928, 0.685410, 0.687895, 0.690384, 0.692875, 0.695368, 0.697864, 0.700363, 0.702864, 0.705366, 0.707871, 0.710378, 0.712886, 0.715395, 0.717906, 0.720417, 0.722929, 0.725442, 0.727956, 0.730469, 0.732983, 0.735496, 0.738009, 0.740521, 0.743033, 0.745543, 0.748052, 0.750559, 0.753064, 0.755568, 0.758068, 0.760567, 0.763062, 0.765555, 0.768044, 0.770530, 0.773012, 0.775489, 0.777962, 0.780431, 0.782895, 0.785353, 0.787807, 0.790254, 0.792695, 0.795131, 0.797559, 0.799981, 0.802396, 0.804804, 0.807204, 0.809596, 0.811980, 0.814355, 0.816722, 0.819080, 0.821429, 0.823768, 0.826097, 0.828417, 0.830726, 0.833024, 0.835312, 0.837589, 0.839854, 0.842108, 0.844350, 0.846580, 0.848798, 0.851003, 0.853195, 0.855374, 0.857540, 0.859693, 0.861831, 0.863956, 0.866067, 0.868163, 0.870245, 0.872311, 0.874363, 0.876400, 0.878421, 0.880426, 0.882416, 0.884390, 0.886347, 0.888288, 0.890213, 0.892121, 0.894012, 0.895886, 0.897743, 0.899583, 0.901405, 0.903210, 0.904997, 0.906766, 0.908517, 0.910250, 0.911966, 0.913662, 0.915341, 0.917001, 0.918642, 0.920265, 0.921869, 0.923455, 0.925021, 0.926569, 0.928098, 0.929607, 0.931098, 0.932570, 0.934023, 0.935456, 0.936871, 0.938266, 0.939643, 0.941000, 0.942338, 0.943657, 0.944957, 0.946238, 0.947499, 0.948742, 0.949966, 0.951171, 0.952357, 0.953524, 0.954673, 0.955803, 0.956914, 0.958007, 0.959081, 0.960137, 0.961174, 0.962193, 0.963195, 0.964178, 0.965143, 0.966091, 0.967021, 0.967933, 0.968828, 0.969705, 0.970566, 0.971409, 0.972236, 0.973045, 0.973838, 0.974615, 0.975375, 0.976119, 0.976847, 0.977560, 0.978256, 0.978937, 0.979603, 0.980253, 0.980889, 0.981509, 0.982115, 0.982706, 0.983283, 0.983846, 0.984395, 0.984930, 0.985452, 0.985960, 0.986455, 0.986937, 0.987406, 0.987862, 0.988306, 0.988738, 0.989158, 0.989566, 0.989962, 0.990347, 0.990721, 0.991083, 0.991435, 0.991776, 0.992107, 0.992427, 0.992737, 0.993038, 0.993328, 0.993610, 0.993882, 0.994145, 0.994399, 0.994644, 0.994881, 0.995110, 0.995330, 0.995543, 0.995748, 0.995946, 0.996136, 0.996319, 0.996495, 0.996664, 0.996827, 0.996983, 0.997133, 0.997277, 0.997415, 0.997548, 0.997675, 0.997796, 0.997913, 0.998024, 0.998130, 0.998232, 0.998329, 0.998422, 0.998510, 0.998594, 0.998675, 0.998751, 0.998824, 0.998893, 0.998959, 0.999021, 0.999081, 0.999137, 0.999191, 0.999241, 0.999289, 0.999334, 0.999377, 0.999418, 0.999456, 0.999492, 0.999526, 0.999558, 0.999588, 0.999617, 0.999643, 0.999669, 0.999692, 0.999714, 0.999735, 0.999754, 0.999773, 0.999790, 0.999805, 0.999820, 0.999834, 0.999847, 0.999859, 0.999870, 0.999881, 0.999890, 0.999899, 0.999908, 0.999915, 0.999922, 0.999929, 0.999935, 0.999941, 0.999946, 0.999951, 0.999955, 0.999959, 0.999963, 0.999966, 0.999969, 0.999972, 0.999975, 0.999977, 0.999979, 0.999981, 0.999983, 0.999985, 0.999986, 0.999988, 0.999989, 0.999990, 0.999991, 0.999992, 0.999993, 0.999994, 0.999994, 0.999995, 0.999996, 0.999996, 0.999997, 0.999997, 0.999997, 0.999998, 0.999998, 0.999998, 0.999998, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 0.999999, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
};

static double MI_mapping_direct(double sinr, int modulationOrder)
{
  int min_index = 0;
  int max_index = 999;
  int index = 0;
  while (max_index - min_index > 1)
    {
      index = (max_index+min_index)/2;
      if (MI_sinr[index] < sinr)
        {
          min_index = index;
        }
      else
        {
          max_index = index;
        }
    }
  switch(modulationOrder)
    {
    case 2:
      return MI_QPSK[index];
    case 4:
      return MI_16QAM[index];
    case 6:
      return MI_64QAM[index];
    default:
      cout << "Invalid modulation order: " << modulationOrder << endl;
      exit(1);
    }
}

static double MI_mapping_inverse(double MI, int modulationOrder)
{
  int min_index = 0;
  int max_index = 999;
  int index = 0;
  double* MI_curve;
  switch(modulationOrder)
    {
    case 2:
      MI_curve = MI_QPSK;
      break;
    case 4:
      MI_curve = MI_16QAM;
      break;
    case 6:
      MI_curve = MI_64QAM;
      break;
    default:
      cout << "Invalid modulation order: " << modulationOrder << endl;
      exit(1);
    }
  while (max_index - min_index > 1)
    {
      index = (max_index+min_index)/2;
      if (MI_curve[index] < MI)
        {
          min_index = index;
        }
      else
        {
          max_index = index;
        }
    }
  return MI_sinr[index];
}

static double
GetMiesmEffectiveSinr (const vector <double> &sinr, int modulationOrder)
{
  double eff_sinr;
  long double sum_I_sinr = 0;
  double beta = 1.1;
  double beta_db = 10*log10(beta);
  for ( auto sinr_value : sinr )
    {
      sum_I_sinr += MI_mapping_direct (sinr_value - beta_db, modulationOrder);
    }
  eff_sinr = MI_mapping_inverse (sum_I_sinr / sinr.size (), modulationOrder) + beta_db;
  return eff_sinr;
}

static double
GetMiesmEffectiveSinr (const vector <double> &sinrs)
{
  AMCModule* amc = new AMCModule();
  double effectiveSinr = -INFINITY;
  for (int modulationOrder=2; modulationOrder<7; modulationOrder+=2)
    {
      double estimated_effsinr = GetMiesmEffectiveSinr(sinrs, modulationOrder);
      int estimated_cqi = amc->GetCQIFromSinr(estimated_effsinr);
      int estimated_mcs = amc->GetMCSFromCQI(estimated_cqi);
      int estimated_modulation_order = amc->GetModulationOrderFromMCS(estimated_mcs);
      if(estimated_modulation_order == modulationOrder)
        {
          effectiveSinr = estimated_effsinr;
        }
    }
  delete amc;
  return effectiveSinr;
}

#endif /* MIESM_EFFECTIVE_SINR_H_ */
